package org.point.dao.impl;

import java.io.Serializable;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.ConvertIndentDao;
import org.point.domain.ConvertIndent;
import org.point.domain.Product;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: ConvertRuleDetailDaoImpl  
 * @Description: TODO(兑换规则明细数据实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:28:17  
 *
 */
@Repository("convertIndentDao")
public class ConvertIndentDaoImpl extends BaseDaoImpl<ConvertIndent, Serializable> implements ConvertIndentDao {

	private static final String SQLID_DELETEPRORDERS = "delProderByIDS";
	
	private static final String SQLID_FINDPRORDERSPAGE = "find_pro_order_page";

	private static final String SQLID_FINDPRORDERCOUNT = "find_pro_order_count";

	private static final String SQLID_INSERTPRORDER = "insert_Prorder";

	private static final String SQLID_DELETEPRORDER = "delProder";

	private static final String SQLID_FINDPRORDERBYID = "searchForProOrder";

	private static final String SQLID_FINDORDERSTAID = "searchForOrderSta";

	private static final String SQLID_SEARCHCOVID = "search_covertid";

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>Title: </p>  
	 * <p>Description: </p>
	 */
	public ConvertIndentDaoImpl() {
		namespace = super.getNamespace();
	}

	public List<ConvertIndent> findProOrder(DoPage<ConvertIndent> page) {
		List<ConvertIndent> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_FINDPRORDERSPAGE, page);
		} catch (Exception e) {
		    throw new RuntimeException("积分规则分类查询数据库错误！", e);
		}
		return records;
	}

	public Integer countProOrder(DoPage<ConvertIndent> page) {
		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_FINDPRORDERCOUNT, page);
		} catch (Exception e) {
			 throw new RuntimeException("商品查询记录错误！", e);
		}
		return result;
	}

	public Integer insertProOder(ConvertIndent record) {
		int result = getSqlSession().insert(namespace + SQLID_INSERTPRORDER , record);
		return result;
	}

	public Integer delProOrderByids(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELETEPRORDERS, map);
		} catch (Exception e) {
			throw new RuntimeException("兑换订单删除错误！", e);
		}
		return result;
	}

	public List<Product> findProOrder(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer delProOrder(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELETEPRORDER, map);
		} catch (Exception e) {
			throw new RuntimeException("兑换订单删除错误！", e);
		}
		return result;
	}

	public Hashtable<Object,Object> selectProOrderBYid(Map<String, Object> map) {
		Hashtable<Object,Object> record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_FINDPRORDERBYID,map);
		} catch (Exception e) {
			throw new RuntimeException("兑换订单查找错误！", e);
		}
		return record;
	}

	public List<String> selectOrderIDs(Map<String, Object> map) {
		List<String> record = null;
		try {
			record = getSqlSession().selectList(namespace + SQLID_FINDORDERSTAID,map);
		} catch (Exception e) {
			throw new RuntimeException("查询订单状态ID错误！", e);
		}
		return record;
	}

	public String searchCovertID(Map<String, Object> map) {
		String record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_SEARCHCOVID, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return record;
	}

	
}
